import {baseEffects, baseReducers, baseState} from "../../../../models/baseModel";

export default {
  namespace: 'seller',

  state: {
    ...baseState,
  },

  reducers: {
    ...baseReducers
  },

  effects: {

    ...baseEffects,

    * getPageInfo({payload}, {call, put}) {

      const p = {
        ...payload,
        baseUrl: getBaseUrl(),
        process: (records) => {

          return records.map(record => {
            return {
              ...record,
              gender: record.gender == 0 ? "未知" : (record.gender == 1 ? "男" : "女"),
              balance: record.balance / 100 + "元"
            };
          });
        }
      }

      yield put({
        type: 'baseGetPageInfo',
        payload: p
      });
    },

    // 保存和修改
    * save({payload}, {put}) {

      if (!!payload.value.memberExpireDate)
        payload.value.memberExpireDate = payload.value.memberExpireDate.format('x');

      yield put({
        type: 'baseSave',
        payload: {...payload, baseUrl: getBaseUrl()}
      });
    },


    // 删除 之后查询分页
    * delete({payload}, {call, put, select}) {

      yield put({
        type: 'baseDelete',
        payload: {...payload, baseUrl: getBaseUrl()}
      });
    },

    * getAll({payload}, {put, call}) {

      yield put({
        type: 'baseGetAll',
        payload: {...payload, baseUrl: getBaseUrl()}
      });
    }
  }

}

function getBaseUrl() {
  return "/seller";
}

